<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改分类')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-type-edit" th:object="${sysType}">
            <input name="typeid" th:field="*{typeid}" type="hidden">
            <input id="treeId" name="ptypeid" type="hidden" th:field="*{ptypeid}" />
            <input id="filter" name="filter"  type="hidden" th:field="*{filter}" />
            <div class="form-group">
                <label class="col-sm-3 control-label">上级分类：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" id="treeName" onclick="selectTypeTree()" readonly="true" th:field="*{parentname}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">附加分类：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" th:value="${filterstr}" type="text" id="filtercheck" onclick="selectfilter()" readonly="true" >
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">分类名称：</label>
                    <div class="col-sm-8">
                        <input name="typename" th:field="*{typename}" class="form-control" type="text">
                    </div>
                </div>
            </div>

            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">排序：</label>
                    <div class="col-sm-8">
                        <input name="sort" th:field="*{sort}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input  id="state" type="checkbox"  th:checked="${sysType.state == 0 ? true : false}">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/type";
        $("#form-type-edit").validate({
            rules:{
                typename: "required",

            },
            focusCleanup: true
        });
        /*部门管理-修改-选择部门树*/
        function selectTypeTree() {
            var deptId = $("#treeId").val();
            var excludeId = $("input[name='typeid']").val();
            if(deptId > 0) {
                var options = {
                    title: ' 分类选择',
                    width: "380",
                    url: prefix + "/selectTypeTree/" + $("#treeId").val() + "/" + excludeId,
                    callBack: doSubmit
                };
                $.modal.openOptions(options);
            } else {
                $.modal.alertError("父类不能选择");
            }
        }
        function selectfilter() {
           /* var filter = $("#filter").val();
            if(filter) {
                var options = {
                    title: ' 附加分类选择',
                    width: "380",
                    url: prefix + "/selectfilter/" + $("#filter").val(),
                    callBack: doSubmit1
                };
                $.modal.openOptions(options);
            }*/
            $.modal.open("关联分类",prefix + "/selectfilter/" + $("#filter").val(),200,300,doSubmit1);
        }
        function doSubmit1(index, layero){
            var body = $.modal.getChildFrame(index);
            var checkedItems =$(body).find('input[type="checkbox"]:checked');
            console.log(checkedItems);
            //alert(checkedItems);
            var arr=[];
            var str=[];
            checkedItems.each(function(i) {
                arr.push($(checkedItems[i]).val());
                str.push($(checkedItems[i]).attr("name"));
            });
            $("#filter").val(arr.join(","));
            $("#filtercheck").val(str.join(","));
            $.modal.close(index);

        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowLastLevel(tree)) {
                var body = $.modal.getChildFrame(index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                $.modal.close(index);
            }
        }
        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-type-edit").serializeArray();
                var state = $("input[id='state']").is(':checked') == true ? 0 : 1;
                data.push({"name": "state", "value": state});
                $.operate.save(prefix + "/edit", data);
            }
        }

    </script>
</body>
</html>